package com.shop.loan.proxy;

import com.shop.loan.model.view.LoanOrderByOld;
import com.shop.loan.util.LoanOrderUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import xyz.erupt.annotation.fun.DataProxy;
import xyz.erupt.annotation.model.Row;
import xyz.erupt.annotation.query.Condition;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@Service
public class LoanOrderByOldProxy implements DataProxy<LoanOrderByOld> {

    @Resource
    LoanOrderUtil loanOrderUtil;

    @Override
    public String beforeFetch(List<Condition> conditions) {
        return loanOrderUtil.getOrderListBeforeFetch("LoanOrderByOld", conditions);
    }

    @Override
    public void afterFetch(Collection<Map<String, Object>> list) {
        loanOrderUtil.setOrderListData(list);
    }

    @Override
    public List<Row> extraRow(List<Condition> conditions) {
        String sqlEx = loanOrderUtil.getOrderListBeforeFetchByMybatis("ord", "LoanOrderByOld");
        if (!StringUtils.hasText(sqlEx)) {
            sqlEx = "ord.order_num > 1";
        } else {
            sqlEx = sqlEx + " and ord.order_num > 1";
        }
        return loanOrderUtil.setOrderListSumRow(sqlEx);
    }
}
